package com.me.mysqladmin.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import javax.sql.RowSet;

import org.springframework.stereotype.Repository;

import com.me.mysqladmin.dao.TableDataDAO;
import com.me.mysqladmin.entity.Location;
import com.me.mysqladmin.entity.PrimaryKey;
import com.me.mysqladmin.entity.TableData;
import com.me.mysqladmin.util.RowSetUtil;

@Repository("tableDataDAO")
public class TableDataDAOImpl extends BaseDAOImpl<TableData> implements TableDataDAO {
	// 集中定义SQL语句
	private static String QUERY_ALL_DATA = "SELECT * FROM ";

	@Override
	protected List<TableData> toEntities(RowSet rs) {
		return RowSetUtil.toEntiyList(rs, TableData.class);
	}
	
	@Override
	public List<Map<String, Object>> queryDataMap(Location loc) {
		String databaseName = loc.getDatabaseName();
		String tableName = loc.getTableName();
		try {
			return queryMap(QUERY_ALL_DATA + databaseName + "." + tableName);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return Collections.emptyList();
	}

	@Override
	public Integer deleteByPk(PrimaryKey key) {
		// TODO Auto-generated method stub
		return null;
	}
}


